package com.moon.service;

import com.moon.domain.People;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;

/**
 * @author ：xxx
 * @description：TODO
 * @date ：2024/04/09 15:20
 */
public class Test {

    public static void main(String[] args) {
        People yellow = new People().setName("黄狗").setBrithDay(buildDate("2024-04-07"));
        People white = new People().setName("白狗").setBrithDay(buildDate("2024-04-05"));
        People red = new People().setName("红狗").setBrithDay(buildDate("2024-04-08"));
        People green = new People().setName("绿狗").setBrithDay(buildDate("2024-04-06"));

        ArrayList<People> people = new ArrayList<>();

        people.add(yellow);
        people.add(white);
        people.add(red);
        people.add(green);


        String name = people.stream().sorted(Comparator.comparing(People::getBrithDay).reversed())
                .map(People::getName).findFirst().orElse(null);
        System.out.println(name);
    }

    /**
     *
     * @param date 2024-04-08
     * @return
     */
    public static Date buildDate(String date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
